package com.example.jetpacklearn

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import kotlinx.android.synthetic.main.activity_player.*

class PlayerActivity : AppCompatActivity(),
    View.OnClickListener {

    private val playerPresenter by lazy {
        PlayerPresenter.instance
    }

    companion object {
        private const val TAG = "PlayerActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_player)


        btnPlayPlayerNext.setOnClickListener(this)
        btnPlayPlayerPrevious.setOnClickListener(this)

        initDataListener()
    }

    private fun initDataListener() {
        playerPresenter.currentMusic.addListener (this){
            Log.d(TAG, "initDataListener: ${it?.title}")
        }

        playerPresenter.currentLifeMusic.observe(this) {
            Log.d(TAG, "initDataListener life: ${it?.title}")
        }
    }


    override fun onClick(v: View?) {
        when (v) {
            btnPlayPlayerNext -> {
                playerPresenter.doPlayNext()
            }
            btnPlayPlayerPrevious -> {
                playerPresenter.doPlayPrevious()
            }
        }
    }
}